package list;

public class LinkedLists {
    private static class LinkedListNode<T> {
        T data;
        LinkedListNode<T> next;

        private LinkedListNode(T data, LinkedListNode<T> next) {
            this.data = data;
            this.next = next;
        }

        private LinkedListNode(LinkedListNode<T> data) {
            this.data = data.data;
        }

        @Override
        public String toString() {
            return "LinkedListNode{" +
                    "data=" + data +
                    '}';
        }
    }

    private static class LinkedList<T extends Comparable<T>> {
        private LinkedListNode<T> head;

        private LinkedList(LinkedListNode<T> head) {
            this.head = head;
        }

        public void insert(LinkedListNode<T> node) {
            if (node == null) return;
            LinkedListNode<T> current = this.head;
            if (this.head == null){
                this.head = new LinkedListNode<T>(node);
                return;
            }

            while (current != null) {
                if(current.data.compareTo(node.data)<0){
                    current = current.next;
                }else{
                    LinkedListNode<T> newNode = new LinkedListNode<T>(node);
                    newNode.next=current.next;
                    current.next=newNode;
                    return;
                }
            }

        }

    }


}
